﻿var VideoNetSchool = {
    Register: {},
    FindPwd: {},
    Login: {},
    Calendar:{}
};
var pageSize = 6;
var pCount = 0;



VideoNetSchool.Login = {
    ChkPwd: function() {
        var pwd = $("[DataField='VU_Password']").val();
        if (pwd == "" || pwd == null) { $("#spPass").html("不修改请留空！"); }

        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "ChkPwd", PostData: pwd },
                function(e) {
                    if (e == "Success") {
                        $("#spPass").html("密码输入正确！");
                        $("#hfUp").val("");
                    } else if (e == "False") {
                        $("#spPass").html("<font color=red>原始密码输入错误，请检查！</font>");
                        $("#hfUp").val("False");

                        return;
                    } else {
                        $("#spPass").html("不修改请留空！");
                        return;
                    }
                }
            );

    },
    Modify: function(ctrol) {
        var newpwd = $("[DataField='newPwd']").val();
        var surepwd = $("[DataField='SurePassWord']").val();

        if (newpwd != surepwd) {
            $("#spSure").html("两次密码输入不一致！请检查！");
            return;
        } else {
            if (newpwd != "" && surepwd != "") {
                $("#spSure").html("校验成功！");
            } else {
                $("#spSure").html();
            }
        }
        if (ctrol == "C") {
            return;
        }
        if ($("#hfUp").val() == "False") {
            alert("对不起原始密码错误不能修改！");
            return;
        } 

        registFormData = VideoNetSchoolCore.Form.GetDivFormData($("#modify"));
        var jsonDataString = $.toJSON(registFormData);

        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "Modify", PostData: jsonDataString, strValue: surepwd },
                function(e) {
                    if (e == "True") {
                        alert("成功修改");
                    } else {
                        alert("修改失败，请联系管理员！");
                        return;
                    }
                }
            );

    },
    UserLogin: function(returnUrl) {
        var uname = $("[DataField='UserName']").val();
        var pwd = $("[DataField='PassWord']").val();
        var schoolID = $("[DataField='SchoolID']").val();
        if (uname == "") {
            alert("对不起，请输入用户名！");
            return;
        }
        if (pwd == "") {
            alert("对不起，请输入密码！");
            return;
        }
        $("[datafield='divLogin']").hide();
        $("#divLoading").show();

        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "UserLogin", PostData: uname, strValue: pwd, SchoolID: schoolID },
                function(e) {
                    if (e == "Success") {
                        if (returnUrl != "") {
                            window.location.href = returnUrl;
                        } else {
                            //  window.location.href = 'UserCenter/UserCourseCalendar.aspx';
                            window.location.href = BaseUrl;
                        }
                    } else {
                        alert(e);
                        $("#divLoading").hide();
                        $("[datafield='divLogin']").show();
                        return;
                    }
                }
            );

    },
    LoginOut: function(returnUrl) {
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "LoginOut" },
                function(e) {
                    if (e == "Success") {
                        window.location.href = returnUrl;
                    }
                }
            );
    }
};

VideoNetSchool.Comment = {
    PostComment: function() {
        var comment = $("#txtComment").val();
        var CourselistID = $("[datafield = 'CourselistID']").val();
        if (CourselistID == "") {
            alert("请先选择课程再评论！");
            return;
        }
        if (comment == "请先选择课程再评论!" && CourselistID == "") {
            alert("请先选择课程再评论！");
            return;
        }
        if (comment == "请先选择课程再评论!" && CourselistID != "") {
            alert("请填写评论内容！");
            return;
        }
        if (comment == "请先选择课程再评论!" || comment == "请输入评论！") {
            alert("请填写评论内容！");
            return;
        }
        if (comment == "") {
            alert("请填写评论内容！");
            return;
        }
        
        if (CourselistID == "") {
            alert("请先选择课程再评论！");
            return;
        }

        VideoNetSchoolCore.Form.PostData(
                                        InitPostUrl,
                                        { OpType: "SubmitComment", PostData: CourselistID, strValue: comment },
                                            function(e) {

                                                if (e == "Success") {
                                                    alert("提交成功！");
                                                    $("#txtComment").html("请输入评论！");
                                                    VideoNetSchool.Calendar.LoadComment(CourselistID, 1, pageSize);

                                                } else {
                                                    alert("对不起提交失败！");
                                                    return;
                                                }
                                            });
    }
};
VideoNetSchool.Register = {
    Verify: function(OpType) {
        var uname = $("[DataField='VU_loginname']").val(); 
        if (uname == "") {
            $("#spUname").html("对不起请输入用户名！");
            return;
        } else {
            $("#spUname").html("");
        }
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: OpType, strValue: uname },
                function(e) {
                    switch (OpType) {
                        case "VerifyUserName":
                            if (e == "False") {
                                $("#spUname").html("对不起用户名已经被占用！");
                            } else {
                                $("#spUname").html("√恭喜你用户名可以使用！");
                            }
                            break;
                        case "FindPwd":
                            if (e != "True") {
                                $("#spUname").html("对不起用户名不存在，请检查！");
                            } else {
                                $("#spUname").html("");

                            }
                            break;
                    }



                }
            );
    },
    Regist: function() {
        registFormData = VideoNetSchoolCore.Form.GetDivFormData($("#regist"));
        var jsonDataString = $.toJSON(registFormData);
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "Regist", PostData: jsonDataString },
                function(e) {

                    if (e == "1") {
                        window.location.href = 'UserCenter/UserCourseCalendar.aspx?SchoolId=' + $("[DataField='SchoolID']").val(); ;
                    } else {
                        alert("注册失败，请联系管理员！");
                        return;
                    }
                }
            );
    }

};


VideoNetSchool.FindPwd = {
    UserFindPwd: function() {
        var strValue = $("#txtCheckCode").val();
        if ($("[DataField = 'VU_loginname']").val()=="") {
            alert("对不起请输入用户名！");
            return;
        }
        if ($("[DataField = 'VU_email']").val()=="") {
            alert("对不起请输入邮箱！");
            return;
        }
        var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;

        if (!myreg.test($("[DataField = 'VU_email']").val())) {
            alert("对不起，你输入的邮箱格式不正确！请检查！");
            return;
        }


        FindPwdForm = VideoNetSchoolCore.Form.GetDivFormData($("#findPwd"));
        var jsonDataString = $.toJSON(FindPwdForm);
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "SendUserPwd", PostData: jsonDataString, strValue: strValue },
                function(e) {
                    if (e == "ErrorVCode") {
                        alert("对不起，验证码输入有误！");
                        return;
                    }
                    if (e == "True") {
                        window.location.href = 'FindPwdSuccess.aspx?SchoolId=' + $("[DataField='SchoolID']").val(); ;
                    } else {
                        alert("邮件发送失败请检查！");
                        return;
                    }
                }
            );
    }

};
VideoNetSchool.ControlCenter = {
    HidControl: function(lid, controlid) {
        if ($("#" + controlid).is(":hidden")) {
            $("#" + controlid).show(300);
            $("#" + lid).removeClass("icon_collapse").addClass("icon_expand");
        } else {
            $("#" + controlid).hide("fast");
            $("#" + lid).removeClass("icon_expand").addClass("icon_collapse");
        }
    }
};

VideoNetSchool.Calendar = {
    LoadClass: function(CurrentIndex, CourseID, CourseDate, RoomId, StartTime, EndTime) {
    var SchoolId = $("[DataField = 'SchoolId']").val();
        VideoNetSchool.Calendar.LoadComment(CourseID, 1, pageSize);
        VideoNetSchoolCore.Form.PostData(
                CalendarUrl,
                { OpType: "CalendarCourseList", CurrentIndex: CurrentIndex, CourseID: CourseID, CourseDate: CourseDate, RoomId: RoomId, StartTime: StartTime, EndTime: EndTime,SchoolId:SchoolId},
                function(e) {

                    if (e.ReturnUrl != "") {
                        alert("对不起你的操作已经超时！请重新登陆！");
                        window.location.href = e.ReturnUrl;
                    }
                    if (e.ResultMessage != "") {
                        $("#Player").html(e.ResultMessage);

                    }
                    $("#CourseDesc").html(e.CourseDesc);
                    $("#TeacherName").html(e.TeacherName);
                    $("#CourseName").html(e.CourseName);
                    $("#classInfo").show(300);
                    $("#spTime").empty().html(CourseDate);
                    $("#clsInfo").removeClass("icon_collapse").addClass("icon_expand");
                    $("#hfPageCount").val(e.RtnCount);
                    VideoNetSchool.Calendar.ComputPageCount(e.RtnCount);
                    if (e.RtnCount > 0) {
                        $("#pager").pager({ pagenumber: 1, pagecount: pCount, buttonClickCallback: VideoNetSchool.Calendar.PageClick }); //初始化分页导航
                    }
                    if (e.ReturnValue == null) {
                        $("#v").html("<div id='container'></div><span  id='spanPlayer'><embed src=\"../images/loading.swf\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"opaque\" width=\"645\" height=\"445\"></embed></span>");
                        alert("对不起，当前第" + parseInt(parseInt(CurrentIndex) + 1) + "段视频正在制作中，请稍候访问...");

                        return;
                    }
                    if (e.ReturnValue == "") {
                        $("#v").html("<div id='container'></div><span  id='spanPlayer'><embed src=\"../images/loading.swf\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"opaque\" width=\"645\" height=\"445\"></embed></span>");
                        alert("对不起，当前第" + parseInt(parseInt(CurrentIndex) + 1) + "段视频正在转码，请稍候访问...");
                        return;
                    }
                    if (e.ReturnValue != "") {

                        $("#v").html("<div id='container'></div><span  id='spanPlayer'></span>");
                        $("#spanPlayer").html(e.ReturnValue);
                        return;


                    }


                }
            );

    },
    LoadComment: function(courseId, pageIndex, pageSize) {
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "GetComment", strValue: courseId, pageIndex: pageIndex, PageSize: pageSize },
                function(e) {

                    if (e != "") {
                        $("#spComment").html(e);
                        $("#pager").show();
                    } else {
                        $("#spComment").empty();
                        $("#pager").hide();
                    }

                }
            );
    },
    PageClick: function(pageclickednumber) {

        var pageCount = $("[DataField='PageCount']").val();
        VideoNetSchool.Calendar.ComputPageCount(pageCount);
        var itemID = $("[DataField='CourselistID']").val();
        VideoNetSchoolCore.Form.PostData(
                InitPostUrl,
                { OpType: "GetComment", strValue: itemID, PageIndex: pageclickednumber, PageSize: pageSize },
                function(e) {
                    if (e != "") {
                        $("#spComment").html(e);
                        $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pCount, buttonClickCallback: VideoNetSchool.Calendar.PageClick });
                    }

                }
            );
    },
    ComputPageCount: function(recordCount) {
        if (recordCount % pageSize == 0) {
            pCount = recordCount / pageSize;
        }
        if (recordCount % pageSize > 0) {
            pCount = recordCount / pageSize + 1;
        }

    },
    PreWeek: function() {

        var CourselistID = $("[DataField='CourselistID']").val();
        var CourseDate = $("[DataField='CourseDate']").val();
        var RoomId = $("[DataField='RoomId']").val();
        var StartTime = $("[DataField='StartTime']").val();
        var EndTime = $("[DataField='EndTime']").val();
        var CurrentMinY = $("[DataField='CurrentMinY']").val();
        var CurrentMinMon = $("[DataField='CurrentMinMon']").val();
        var CurrentMinDay = $("[DataField='CurrentMinDay']").val();
        var SchoolId = $("[DataField = 'SchoolId']").val();

        VideoNetSchoolCore.Form.PostData(
                CalendarUrl,
                { OpType: "PreWeek", CourseID: CourselistID, CourseDate: CourseDate, RoomId: RoomId, StartTime: StartTime, EndTime: EndTime, CurrentY: CurrentMinY, CurrentM: CurrentMinMon, CurrentMd: CurrentMinDay,SchoolId:SchoolId },
                function(e) {
                    if (e != "") {
                        $("#spCourseList").empty().html(e.ResultMessage);
                        $("[DataField='CurrentMinY']").val(e.RtnMinYear);
                        $("[DataField='CurrentMinMon']").val(e.RtnMinMonth);
                        $("[DataField='CurrentMinDay']").val(e.RtnMinDay);
                        $("[DataField='CurrentMaxY']").val(e.RtnMaxYear);
                        $("[DataField='CurrentMaxMon']").val(e.RtnMaxMonth);
                        $("[DataField='CurrentMaxDay']").val(e.RtnMaxDay);

                    }

                }
            );
    },
    NextWeek: function() {
        var CourselistID = $("[DataField='CourselistID']").val();
        var CourseDate = $("[DataField='CourseDate']").val();
        var RoomId = $("[DataField='RoomId']").val();
        var StartTime = $("[DataField='StartTime']").val();
        var EndTime = $("[DataField='EndTime']").val();
        var CurrentMaxY = $("[DataField='CurrentMaxY']").val();
        var CurrentMaxMon = $("[DataField='CurrentMaxMon']").val();
        var CurrentMaxDay = $("[DataField='CurrentMaxDay']").val();
        var SchoolId = $("[DataField = 'SchoolId']").val();
        VideoNetSchoolCore.Form.PostData(
                 CalendarUrl,
                { OpType: "NextWeek", CourseID: CourselistID, CourseDate: CourseDate, RoomId: RoomId, StartTime: StartTime, EndTime: EndTime, CurrentY: CurrentMaxY, CurrentM: CurrentMaxMon, CurrentMd: CurrentMaxDay,SchoolId:SchoolId },
                function(e) {
                    if (e != "") {
                        $("#spCourseList").empty().html(e.ResultMessage);
                        $("[DataField='CurrentMinY']").val(e.RtnMinYear);
                        $("[DataField='CurrentMinMon']").val(e.RtnMinMonth);
                        $("[DataField='CurrentMinDay']").val(e.RtnMinDay);
                        $("[DataField='CurrentMaxY']").val(e.RtnMaxYear);
                        $("[DataField='CurrentMaxMon']").val(e.RtnMaxMonth);
                        $("[DataField='CurrentMaxDay']").val(e.RtnMaxDay);
                    }

                }
            );
    }

};
